package judesart.app.client;

import judesart.app.client.controller.SystemController;
import judesart.app.client.controller.SystemControllerAsync;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class ApplicationProperties {
	
	private static SystemControllerAsync systemController = SystemController.Util.getInstance();
	
	private static Boolean production = null;
	
	private static String version = null;
	
	public static void init(){
		systemController.isProduction(new AsyncCallback<Boolean>() {
			
			@Override
			public void onSuccess(Boolean result) {
				Log.debug("Application properties - production : [" + result + "]");
				production = result;
			}
			
			@Override
			public void onFailure(Throwable caught) {
				Log.error("Unable to get production value from server", caught);
			}
		});
		systemController.getApplicationVersion(new AsyncCallback<String>() {
			@Override
			public void onFailure(Throwable caught) {
				Log.error("Unable to get production value from server", caught);
			}
			@Override
			public void onSuccess(String result) {
				Log.debug("Application properties - version : [" + result + "]");
				version = result;
			}
		});
	}
	
	public static boolean isProduction() {
		return production != null && production.booleanValue();
	}
	
	public static String getVersion() {
		return version;
	}
	
	public static boolean isInitialized(){
		return production != null && version != null;
	}
	
}
